/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package distribuicao;


import java.rmi.Remote;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

import padroes.singleton.Singleton;

import dao.DAO;
import dao.PesrsitDAO;


public class ServerRMI extends Thread {

   
    public final int PORTA = 5555;
    private Registry r;

    public ServerRMI() {
    }

    @Override
    public void run() {
        try {

        	r = LocateRegistry.createRegistry(PORTA);
        	
        	PesrsitDAO s = Singleton.getInstancia();
        	r.rebind("Servidor", (Remote) s);
            
           

        } catch (Exception e) {
            e.printStackTrace();
        }
        super.run();
    }


    /*
     * Remove as interfaces do RMI do jogo e fecha o mesmo...
     */
    public void desligarServerRMI() {
        try {
            r.unbind("servidor");
            System.exit(0);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
